import { addMonth } from "./addMonth"
import { getMonthDays } from "./getMonthDays"

export function addYear(num: string | number = 1, date: Date = new Date()) {
  let m = date.getMonth()
  num = Number(num)
  date.setFullYear(date.getFullYear() + num)
  if (m < date.getMonth()) {
    date = addMonth(-1, date)
    date.setDate(getMonthDays(date))
  }
  return date
}